package com.learn.mq.controller;

import com.alibaba.fastjson2.JSON;
import com.learn.mq.beans.Person;
import com.learn.mq.param.Message;
import com.learn.mq.param.MessageBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * ClassName:SendMsgController
 * Package:com.learn.mq.controller
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/30 - 17:52
 * @Version:v1.0
 */
@RestController
@Slf4j
public class SendMsgController {

    @Autowired
    private StreamBridge streamBridge;

    @GetMapping("/sendMsg1")
    public boolean sendMsg1(){
        Person person = new Person(1,"张三",new Date(),'男',"18234565645");
        log.info("发送的消息对应的输出通道为hello-out-0，发送的参数为: "+person);
        boolean send = streamBridge.send("hello-out-0",
                                         MessageBuilder
                                        .withPayload(person)
                                        .setHeader("MESSAGE_TAG","GXS-LEARN")
                                        .build());
        log.info("发送消息成功");
        return send;
    }

}
